import java.util.EmptyStackException;

public class StackTest {
    public static void main(String[] args) {
        Stack1 st1 = new Stack1();
        st1.pop();
        st1.push(10);
        st1.push(20);
        st1.push(30);
        System.out.println(st1.pop());
        System.out.println(st1.pop());
        System.out.println(st1.pop());
    }
}

class Node {
    private int data;
    private Node next;

    public Node(int data, Node next) {
        this.data = data;
        this.next = next;
    }

    public int getData() {
        return data;
    }

    public void setData(int data) {
        this.data = data;
    }

    public Node getNext() {
        return next;
    }

    public void setNext(Node next) {
        this.next = next;
    }

    @Override
    public String toString() {
        return "Node{" +
                "data=" + data +
                ", next=" + next +
                '}';
    }
}

class Stack1 {
    Node head;

    public Stack1() {
        head = null;
    }

    public void push(int data) {
        if (head == null) {
            head = new Node(data, null);
        } else {
            head = new Node(data, head);
        }
        System.out.println("push data: " + data);
    }

    public Node pop() {
        if (head == null) {
            System.out.println("no data");
            throw new EmptyStackException();
        } else {
            Node temp = head;
            head = head.getNext();
            return temp;
        }
    }
}



